#!/bin/sh
#
# Startup script for the Common Console Framework

dir=$1
if [ -z "$dir" ]; then
   dir=$PWD
else
   cd $dir
fi

user=$2

# Include the common hmc functions
. $dir/hmcfunctions

setupEnv $dir
echo "CCFW environment is:"
export

cleanupTmp

# fix umask and chmod the data/persist diectories.
umask g+w
chmod -R g+w "$dir/data/persist"

hmcinitlog "The Common Console Framework daemon is being started."

# run the init scripts
runInit $dir $user

# Run the manager forever.
loopCtrl=""
while [ -z "$loopCtrl" ]; do
   if [ -z "$user" ]; then
      runmanagerOnly $dir 
   else
      runmanagerOnly $dir $user
   fi
   hmcinitlog "The Common Console Framework daemon has ended with rc=$jvmRc."
   echo "Common Console Framework daemon ended with rc=$jvmRc."
   case "$jvmRc" in
      102) 
           loopCtrl="halt"
           halt
           ;;
      103) 
           loopCtrl="poweroff" 
           poweroff
           ;;
      101) 
           loopCtrl="reboot" 
           reboot
           ;;
      *) 
           sleep 10
           ;;
   esac
done
